package com.collections;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;

public class CollectionTest {
	public static void main(String[] args) {
		// Maintain the order.
		System.out.println("ArrayList");
		List<String> list = new ArrayList<String>();
		list.add("1");
		list.add("3");
		list.add("2");
		list.add("4");
		list.add("11");
		System.out.println(list);
		Collections.sort(list);
		System.out.println(list);
		System.out.println();
		
		// Undefined order.
		// Allow null key & value.
		System.out.println("HashMap");
		Map<String, String> map = new HashMap<String, String>();
		map.put("1", "aaa");
		map.put("3", "ccc");
		map.put(null, null);
		map.put("2", "bbb");
		System.out.println(map);
		System.out.println();

		// Undefined order.
		// Does not allow null key & value.
		System.out.println("Hashtable");
		Map<String, String> map2 = new Hashtable<String, String>();
		map2.put("b", "bbb");
		map2.put("b", "ccc");
		System.out.println(map2);
		System.out.println();
		
		// Maintain insertion order.
		System.out.println("LinkedHashMap");
		Map<String, String> map3 = new LinkedHashMap<String, String>();
		map3.put("5", "aaa");
		map3.put("4", "bbb");
		map3.put("6", "ccc");
		map3.put("6", "ddd");
		map3.put(null, null);
		System.out.println(map3);
		System.out.println();
		
		// Sort lexicographically.
		System.out.println("TreeMap");
		SortedMap<String, String> map4 = new TreeMap<String, String>();
		map4.put("5", "aaa");
		map4.put("4", "bbb");
		map4.put("6", "ccc");
		map4.put("6", "ddd");
		System.out.println(map4);
		System.out.println();
		
		// Unique key.
		// Undefined order.
		System.out.println("HashSet");
		Set<String> set = new HashSet<String>();
		set.add("4");
		set.add("1");
		set.add("2");
		set.add("1");
		System.out.println(set);
		System.out.println();

		// Unique key.
		// Sort lexicographically.
		System.out.println("TreeSet");
		SortedSet<String> set2 = new TreeSet<String>();
		set2.add("4");
		set2.add("1");
		set2.add("3");
		set2.add("2");
		System.out.println(set2);
		System.out.println();
	}
}